package utils

import (
	"github.com/gin-gonic/gin"
)

type Resource struct {
	*gin.RouterGroup
}

type ResourceInterface interface {
	Index(c *gin.Context)
	Show(c *gin.Context)
	Create(c *gin.Context)
	Update(c *gin.Context)
	Delete(c *gin.Context)
}

func (resource *Resource) Resource(url string, controller ResourceInterface) {
	resource.GET(url, controller.Index)
	resource.GET(url+"/:id", controller.Show)
	resource.POST(url, controller.Create)
	resource.PUT(url+"/:id", controller.Update)
	resource.DELETE(url+"/:id", controller.Delete)
}

func (resource *Resource) Group(relativePath string, handlers ...gin.HandlerFunc) *Resource {
	r := resource.RouterGroup.Group(relativePath, handlers...)
	return &Resource{r}
}

func NewResource(r *gin.RouterGroup) *Resource {
	return &Resource{r}
}
